package com.aloha.auth.config;

import com.aloha.auth.interceptor.AuthInterceptor;
import com.aloha.auth.interceptor.LoginInterceptor;
import com.aloha.auth.support.AuthUtils;
import com.aloha.auth.support.impl.AnnoAuthValidator;
import com.aloha.auth.support.impl.RouterAuthValidator;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zhdai
 * @date 2023/11/9 21:57
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor());
        registry.addInterceptor(new AuthInterceptor()
                .addValidator(new RouterAuthValidator()
                        .addMatch("/user/**", r -> AuthUtils.hasPerm("user"))
                        .addMatch("/keen/**", r -> AuthUtils.hasPerm("keen")))
                .addValidator(new AnnoAuthValidator())
        );
    }
}
